/**
 * Copyright (C) 2016-2019 DSpot Sp. z o.o
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.dspot.declex.handler;

import com.dspot.declex.annotation.ExportRecollect;
import com.dspot.declex.annotation.PutOnAction;
import com.dspot.declex.annotation.Recollect;

import org.ohosannotations.ElementValidation;
import org.ohosannotations.OhosAnnotationsEnvironment;
import org.ohosannotations.handler.BaseAnnotationHandler;
import org.ohosannotations.helper.IdValidatorHelper;
import org.ohosannotations.holder.EComponentHolder;
import org.ohosannotations.rclass.IRClass;

import javax.lang.model.element.Element;

/**
 * 行动程序
 *
 * @since 2021-07-16
 */
public class PutOnActionHandler extends BaseAnnotationHandler<EComponentHolder> {


    /**
     * 在操作处理程序
     *
     * @param environment 环境
     */
    public PutOnActionHandler(OhosAnnotationsEnvironment environment) {
        super(PutOnAction.class, environment);
    }

    @Override
    protected void validate(Element element, ElementValidation valid) {

        if (adiHelper.getAnnotation(element, ExportRecollect.class) != null) {
            valid.addError("@PutOnAction is not available in @ExportRecollect annotated fields");
        }

        if (!adiHelper.hasAnnotation(element, Recollect.class)) {
            valid.addError("@PutOnAction should be used in fields annotated with @Recollect");
        }

        validatorHelper.resIdsExist(element, IRClass.Res.ID, IdValidatorHelper.FallbackStrategy.NEED_RES_ID, valid);
    }

    @Override
    public void process(Element element, EComponentHolder holder) throws Exception {
    }
}
